package com.yanqu.road.server.cmd.activity.yqhotel;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.YqHotelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;

import com.yanqu.road.server.gameplayer.module.activity.yqhotel.YqHotelModule;
import com.yanqu.road.server.manger.activity.yqhotel.YqHotelMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_YQ_HOTEL_OPEN_BUILDING, desc = "阳泉酒家打开建筑")
public class YqHotelOpenBuildCmd extends AbstractCommand {

    int buildingId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        YqHotelProto.YqHotelOpenBuildBuildingReqMsg reqMsg = YqHotelProto.YqHotelOpenBuildBuildingReqMsg.parseFrom(packet.getBytes());
        buildingId = reqMsg.getBuildingId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!YqHotelMgr.activityInTime()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        YqHotelProto.YqHotelOpenBuildBuildingRespMsg.Builder respMsg = player.getModule(YqHotelModule.class).openBuilding(buildingId);
        player.sendPacket(ClientProtocol.U_YQ_HOTEL_OPEN_BUILDING, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            YqHotelProto.YqHotelOpenBuildBuildingRespMsg.Builder respMsg = YqHotelProto.YqHotelOpenBuildBuildingRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_YQ_HOTEL_OPEN_BUILDING, respMsg);
        }
    }
}
